Reference
  Area\Util.txt
  Util\Audio.txt
  Util\Party.txt
  Util\CommonDialog.txt
End Reference

Procedure Main(startAt)

  Dim ac = Nothing

  RegisterCommonEventHandlers()
  AddAreaZone(AddZone("B1", 0, 0, 0, 127, 127, 100), 1)

  AddZone("Entrance", 31, 126, 0)
  
  AddZone("ExitArea1", 31, 127, 0, 32, 127, 0)
  RegisterEventHandler("ExitArea1Enter", ExitArea1_Enter)
  AddZone("Entrance1", 31, 126, 0)

  AddZone("ExitArea2", 49, 0, 0)
  RegisterEventHandler("ExitArea2Enter", ExitArea2_Enter)
  AddZone("Entrance2", 49, 1, 0)

  AddBox("CaveC1_B1", 50, 2, 0, BoxContent.Tool, [RedRing], Nothing)
  AddBox("CaveC1_B2", 69, 5, 0, BoxContent.Tool, [BlackHat], Nothing)
  AddBox("CaveC1_B3", 11, 114, 0, BoxContent.Money, 800, Nothing)
  AddBox("CaveC1_B4", 45, 102, 0, BoxContent.Money, 900, Nothing)
  AddBox("CaveC1_B5", 56, 114, 0, BoxContent.Money, 1000, Nothing)
  AddBox("CaveC1_B6", 71, 74, 0, BoxContent.Money, 1100, Nothing)
  AddBox("CaveC1_B7", 71, 106, 0, BoxContent.Money, 1200, Nothing)
  AddBox("CaveC1_B8", 107, 85, 0, BoxContent.Money, 1300, Nothing)
  AddBox("CaveC1_B9", 102, 58, 0, BoxContent.Money, 1400, Nothing)
  AddBox("CaveC1_B10", 121, 6, 0, BoxContent.Money, 1500, Nothing)
  AddBox("CaveC1_B11", 59, 6, 0, BoxContent.Money, 1600, Nothing)
  AddBox("CaveC1_B12", 35, 14, 0, BoxContent.Money, 1700, Nothing)
  AddBox("CaveC1_B13", 11, 46, 0, BoxContent.Money, 1800, Nothing)
  AddBox("CaveC1_B14", 15, 70, 0, BoxContent.Money, 1900, Nothing)
  AddBox("CaveC1_B15", 38, 82, 0, BoxContent.Money, 2000, Nothing)
  AddBox("CaveC1_B16", 29, 42, 0, BoxContent.Money, 2100, Nothing)
  
  If Not TestFlag("CaveC1_1") Then
    ac = AddStaticActor("StoneWall", 49, 1, 0, [A_StoneWall], StoneWall_Contact)
  End If
  
  SetStepsOfMaterial(4, 20)
  ResetStepsForEncountering()
  
  AddZone("EncZone01", 0, 0, 0, 127, 127, 0)
  RegisterEventHandler("EncZone01Step", EncZone01_Step)

  If startAt = "Entrance1" Then
    DoInsideWarp(startAt, Direction.Up, False)
  Else
    DoInsideWarp(startAt, Direction.Down, False)
  End If
  
  ChangeBGM(Music.Cave)

  NotifyEntered()
  Idle(ProcessInput)
  NotifyExiting()

End Procedure

Procedure ExitArea1_Enter()
  BeginOutsideWarp([Field], "CaveC1a")
End Procedure

Procedure ExitArea2_Enter()
  BeginOutsideWarp([Field], "CaveC1b")
End Procedure

Procedure EncZone01_Step(mat)
  If TestEncountering(mat) Then
    Dim ep = CreateList()
    ep.Add({[E113], [E113], [E113], [E113], [E113]})
    ep.Add({[E114], [E113], [E113], [E113], [E113]})
    ep.Add({[E114], [E114], [E113], [E113]})
    ep.Add({[E114], [E114], [E114]})
    ep.Add({[E115], [E113], [E113], [E113]})
    ep.Add({[E115], [E114], [E113]})
    ep.Add({[E115], [E115]})
    DoNormalBattle(ep)
    ResetStepsForEncountering()
  End If
End Procedure

Procedure StoneWall_Contact()
  DoMsg("（隙間から外の空気が……）")
  Sleep(500)
  DoMsg("（動かせるみたいだ！）")
  If DoYesNoMsg("本当に扉を開いてよろしいですか？") Then
    Sleep(1000)
    RemoveActor("StoneWall")
    Sleep(500)
    SetFlag("CaveC1_1")
    BeginOutsideWarp([Field], "CaveC1b")
  End If
End Procedure
